home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / clisp-li.000 / clisp-li / clisp-1996-07-22 / wildcard / wildcard.lsp < prev    next >
Encoding:
Lisp/Scheme  |  1995-04-18  |  1.1 KB  |  39 lines

  1. ;; Module for wildcard matching in CLISP
  2. ;; Bruno Haible 18.4.1995
  3.  
  4. (in-package "WILDCARD")
  5.  
  6. (export '(match))
  7.  
  8. (use-package "FFI")
  9.  
  10. (def-c-call-out fnmatch (:arguments (pattern c-string)
  11.                                     (string c-string)
  12.                                     (flags int)
  13.                         )
  14.                         (:return-type int)
  15. )
  16.  
  17. ; flags values
  18. (defconstant FNM_PATHNAME     1)
  19. (defconstant FNM_FILE_NAME    1)
  20. (defconstant FNM_NOESCAPE     2)
  21. (defconstant FNM_PERIOD       4)
  22. (defconstant FNM_LEADING_DIR  8)
  23. (defconstant FNM_CASEFOLD    16)
  24.  
  25. (defun match (pattern string &key (start 0) (end nil) (case-insensitive nil))
  26.   ; Prepare the string.
  27.   (unless (and (eql start 0) (null end))
  28.     (unless end (setq end (length string)))
  29.     (setq string (make-array (- end start) :element-type 'character
  30.                                            :displaced-to string
  31.                                            :displaced-index-offset start
  32.   ) )            )
  33.   ; Match.
  34.   (zerop
  35.     (fnmatch pattern string
  36.              (logior FNM_PATHNAME (if case-insensitive FNM_CASEFOLD 0))
  37.   ) )
  38. )
  39.